<CFSET sDate1 = DATEFORMAT(Now(),"mm/dd/yyyy")>
	<CFSET sWarn="">

	<!--- define action --->
	<CFIF IsDefined("form.save")>
		<CFSWITCH EXPRESSION="#form.save#">
		<CFCASE VALUE="Save ">
			<CFSET nAction=1>
		</CFCASE>
		<CFCASE VALUE="Replicate">
			<CFSET nAction=2>
		</CFCASE>
		<CFCASE VALUE="Update">
			<CFSET nAction=3>
		</CFCASE>
		<CFCASE VALUE="Copy">
			<CFSET nAction=4>
		</CFCASE>
		</CFSWITCH>
	<CFELSEIF IsDefined("form.savemail")>
		<CFSWITCH EXPRESSION="#form.savemail#">
		<CFCASE VALUE="Save  and eMail">
			<CFSET nAction=1>
		</CFCASE>
		<CFCASE VALUE="Replicate and eMail">
			<CFSET nAction=2>
		</CFCASE>
		<CFCASE VALUE="Update and eMail">
			<CFSET nAction=3>
		</CFCASE>
		</CFSWITCH>
	<CFELSEIF IsDefined("url.SaveFF")>
		<CFSET nAction=3>
	</CFIF>
	<!--- get Editable groups for originator --->
	<CFQUERY NAME="getECRTFORMSGROUP" DATASOURCE="#client.company_dsn#">
		SELECT FIELDGROUP FROM ECRTFORMSGROUP
		WHERE FORMCODE='#GetForm.FORMCODE#'
			AND FORMDETAILCODE='#GetForm.FORMCODE#'
			AND PROCESSCODE = '#GetForm.PROCESSCODE#'
			AND ACTIVITYID = 'ORIGINATOR'
	</CFQUERY>
	<CFSET sLastFieldGrp = "">
	<CFSET lstEditableGrp = getECRTFORMSGROUP.FIELDGROUP>
	
	<!--- check if user attached file --->
	<CFSET lAttach=false>
	<CFLOOP FROM=1 TO=6 INDEX="x">
		<CFIF IsDefined("form.eformfileattachment" & x)>
			<CFIF Trim(Evaluate("form.eformfileattachment#x#")) NEQ "">
				<CFSET lAttach=true>
				<CFBREAK>
			</CFIF>
		</CFIF>
		<CFIF IsDefined("form.eformlinkdesc" & x) AND IsDefined("form.eformlinkattach" & x)>
			<CFIF Trim(Evaluate("form.eformlinkattach#x#")) NEQ "http://" AND Evaluate("form.eformlinkdesc#x#") NEQ "">
				<CFSET lAttach=true>
				<CFBREAK>
			</CFIF>
		</CFIF>
	</CFLOOP>
	<CFIF isDefined("form.save") AND form.save NEQ "Replicate">
		<CFSET GetEntry.ATTACHMENTCODE =  "">
		<!---updated by jep. 012308. GetEntry is not needed for new entry
		<CFQUERY NAME="GetEntry" DATASOURCE="#table_dsn#">
			SELECT *
			FROM #GetForm.TABLENAME_FK#
			WHERE
				(PERSONNELIDNO       = '#GetEmployee.PERSONNELIDNO#')
				<CFLOOP  INDEX="x" FROM="1" TO="5">
					<CFIF evaluate("GetForm.PK_FIELD" & x) NEQ "" AND IsDefined("url." & #evaluate("GetForm.PK_FIELD" & x)#)>
						<CFSET theVal = evaluate("url." & evaluate("GetForm.PK_FIELD" & x))>
						AND (#ucase(evaluate("GetForm.PK_FIELD" & x))# = '#theVal#')
					</CFIF>
				</CFLOOP>
		</CFQUERY>
		--->	
	<CFELSEIF isDefined("form.save") AND form.save EQ "Replicate">
		<CFQUERY NAME="GetEntry" DATASOURCE="#table_dsn#">
			SELECT *
			FROM #GetForm.TABLENAME_FK#
			WHERE
				(PERSONNELIDNO       = '#GetEmployee.PERSONNELIDNO#')
				<CFLOOP  INDEX="x" FROM="1" TO="5">
					<CFIF evaluate("GetForm.PK_FIELD" & x) NEQ "" AND IsDefined("form.old" & #evaluate("GetForm.PK_FIELD" & x)#)>
						<CFSET theVal = evaluate("Form.old" & evaluate("GetForm.PK_FIELD" & x))>
						AND (#ucase(evaluate("GetForm.PK_FIELD" & x))# = '#theVal#')
					</CFIF>
				</CFLOOP>
				<!---
				<CFLOOP  INDEX="x" FROM="1" TO="5">
					<CFIF evaluate("GetForm.PK_FIELD" & x) NEQ "">
						<CFSET theVal = evaluate("Form.edt" & evaluate("GetForm.PK_FIELD" & x))>
						AND (#ucase(evaluate("GetForm.PK_FIELD" & x))# = '#theVal#')
					</CFIF>
				</CFLOOP>
				--->
		</CFQUERY>
	</CFIF>
	<!--- save records (add or copy) --->
	<CFIF nAction IS 1 OR nAction IS 2>
		<CFQUERY NAME="GetDefaultValues" DATASOURCE="#client.global_dsn#">
			SELECT COLUMNNAME, DEFAULTVALUE
			FROM GRGBOSETABLEFIELDS
			WHERE TABLENAME = '#getform.TABLENAME_FK#' AND DEFAULTVALUE <> ''
		</CFQUERY>
		<!--- recreate autogen field value to avoid duplicate record error --->
		<CFSET sAutoGen="">
		<CFSET y = 1>
		<CFLOOP QUERY="GetFields">
			<CFQUERY DATASOURCE="#client.global_dsn#" NAME="qryGSTAUTOGENFIELD">
				SELECT *
				FROM GSTAUTOGENFIELD
				WHERE TABLENAME = '#getform.TABLENAME_FK#' AND
					  FIELDNAME = '#GetFields.COLUMNNAME#'
			</CFQUERY>
			<CFIF qryGSTAUTOGENFIELD.RecordCount>
				<!--- Added by Maan 08112007, check for existing value --->
				<CFQUERY NAME="checkEntry" DATASOURCE="#table_dsn#">
					SELECT * FROM #getform.TABLENAME_FK#
					WHERE #GetFields.COLUMNNAME# = '#Evaluate("form.edt" & GetFields.COLUMNNAME)#'
				</CFQUERY>
				<CFSET arrAutoGen = ArrayNew(2)>
				<CFSET sAutoGenFld = "">
				<CFIF checkEntry.RECORDCOUNT NEQ 0> <!--- entry exists --->
					<CFSET sAutoGenFld = ListAppend(sAutoGenFld,qryGSTAUTOGENFIELD.FIELDNAME)>
					<CFIF qryGSTAUTOGENFIELD.WITHDATE EQ "Y">
						<CFMODULE TEMPLATE="#client.common_path#autogenfield.cfm"
							SEEDKEY="#qryGSTAUTOGENFIELD.SEEDKEY#"
							CODELENGTH="#qryGSTAUTOGENFIELD.CODELENGTH#"
							COLUMNNAME="#GetFields.COLUMNNAME#"
							TABLENAME_FK="#getform.TABLENAME_FK#"
							DATASOURCE="#table_dsn#"
							WITHDATE="#qryGSTAUTOGENFIELD.WITHDATE#">
							<CFSET sValue=AUTOGENVALUE>
							<CFSET arrAutoGen[y][1] = sValue>
							<CFSET arrAutoGen[y][2] = GetFields.COLUMNNAME>
							<CFSET y = y + 1>
							<CFIF sValue NEQ Evaluate("Form.edt" & GetFields.COLUMNNAME)>
								<CFSET xDummy=Evaluate("Form.edt" & GetFields.COLUMNNAME & "='" & sValue & "'")>
								<CFSET sAutoGen=sAutoGen & "#GetFields.COLUMNDESC# was changed to #sValue#.<BR>">
							</CFIF>
					<CFELSE>
					<!--- WITHDATE eq "N" --->
						<CFMODULE TEMPLATE="#client.common_path#cfm_autogen_bose.cfm"
							COLUMNNAME="#GetFields.COLUMNNAME#"
							TABLENAME="#getform.TABLENAME_FK#"
							DATASOURCE="#table_dsn#">  
							<CFSET sValue=AUTOGENVALUE>
							<CFSET arrAutoGen[y][1] = sValue>
							<CFSET arrAutoGen[y][2] = GetFields.COLUMNNAME>
							<CFSET y = y + 1>
							<CFIF sValue NEQ Evaluate("Form.edt" & GetFields.COLUMNNAME)>
								<CFSET xDummy=Evaluate("Form.edt" & GetFields.COLUMNNAME & "='" & sValue & "'")>
								<CFSET sAutoGen=sAutoGen & "#GetFields.COLUMNDESC# was changed to #sValue#.<BR>">
							</CFIF>
					</CFIF>
				<CFELSE>
				<!--- otherwise, leave it as it is. --->
					<CFSET sValue= Evaluate("form.edt" & COLUMNNAME)>
				</CFIF>
			</CFIF>
		</CFLOOP>

		<!--- check for existence --->
		<CFQUERY NAME="IsExist" DATASOURCE="#table_dsn#">
	  		SELECT COUNT(*) AS RECCOUNT
			FROM #GetForm.TABLENAME_FK#
			WHERE
				(PERSONNELIDNO       = '#GetEmployee.PERSONNELIDNO#')
				<CFLOOP  INDEX="x" FROM="1" TO="5">
					<CFIF evaluate("GetForm.PK_FIELD" & x) NEQ "">
						<CFSET theVal = evaluate("Form.edt" & evaluate("GetForm.PK_FIELD" & x))>
						AND (#ucase(evaluate("GetForm.PK_FIELD" & x))# = '#theVal#')
					</CFIF>
				</CFLOOP>
	  	</CFQUERY>

		<!--- there are duplicate records 
		<CFIF IsExist.RECCOUNT NEQ 0>
			<CFSET sWarn = "Duplicate record found. Operation aborted.<BR>">
		<CFELSE>--->
			<!--- check for late application --->
			<CFIF GetForm.FLDFORLATEAPPS NEQ "" AND Evaluate("IsDefined('Form.edt" & GetForm.FLDFORLATEAPPS & "')")>
				<CFSET sValue=Evaluate("Form.edt" & GetForm.FLDFORLATEAPPS)>
				<CFIF Trim(sValue) IS "">
					<CFSET sValue="01/01/1900">
				</CFIF>
				<CFSET dCutOffDate=Now()>

				<CFIF GetForm.GRACEPRDLATEAPPS NEQ "" AND GetForm.GRACEPRDLATEAPPS NEQ 0>
					<CFIF GetForm.LATEAPPSMODE IS 1>
						<CFSET nGracePrd=(GetForm.GRACEPRDLATEAPPS * -1)>
					<CFELSE>
						<CFSET nGracePrd=GetForm.GRACEPRDLATEAPPS>
					</CFIF>
					<CFSET dCutOffDate=DateAdd("d", nGracePrd, dCutOffDate)>
				</CFIF>

				<CFSET nValue=DateCompare(dCutOffDate, sValue, "d")>
			<CFELSE>
				<CFSET nValue=1000>
			</CFIF>

			<CFIF (nValue IS 1 OR nValue IS 0) AND GetForm.LATEAPPSMODE IS "1">
				<CFSET sWarn = "Late Application is not accepted. Operation aborted.<BR>">
			<CFELSEIF (nValue IS -1 OR nValue IS 0) AND GetForm.LATEAPPSMODE IS "2">
				<CFSET sWarn = "Advance Application is not accepted. Operation aborted.<BR>">
			<CFELSE>
				<CFTRY>
					<!--- audit trail --->
					<CFSET sAuditAction="A">
					<CFSET qryAuditFields=GetFields>
					<CFSET sAuditTablename=GetForm.TABLENAME_FK>
					<CFSET sAuditTableLevel=GetLevelID.LEVELID>
					<CFSET aAuditExtraField=ArrayNew(2)>
					<CFSET aAuditExtraField[1][1]="PERSONNELIDNO">
					<CFSET aAuditExtraField[1][2]="#GetEmployee.PERSONNELIDNO#">
					<CFLOOP QUERY="GetFields">
						<CFIF #COLUMNTYPE# EQ "ftMemo">
							<CFSET myColType="ftMemo">
							<CFBREAK>
						<CFELSE>
							<CFSET myColType="ftString">
						</CFIF>
					</CFLOOP>
					<CFINCLUDE TEMPLATE="../audittrail/_audittraildata.cfm">
					<CFSET lCanAttach=true>
					<!---<CFSET sAttachmentCode=CreateUUID()>--->
					<CFSET y = y - 1>
					<CFQUERY NAME="InsertEntry" DATASOURCE="#table_dsn#">
						INSERT
						INTO #GetForm.TABLENAME_FK# (
							PERSONNELIDNO,
							<CFOUTPUT QUERY="GetFields">
								#COLUMNNAME#<CFIF CurrentRow NEQ RecordCount>,</CFIF>
							</CFOUTPUT>
							,RECCREATEDBY
							,RECDATECREATED
							,USERID
							,DATELASTUPDATE
							,TIMELASTUPDATE 
							<CFIF isDefined("GetEntry.ATTACHMENTCODE") AND GetEntry.ATTACHMENTCODE NEQ "">
								,ATTACHMENTCODE
							</CFIF>
							<!---<CFIF lAttach OR isDefined("GetFields.ATTACHMENTCODE")>
								,ATTACHMENTCODE
							</CFIF>--->
						) VALUES (
							'#GetEmployee.PERSONNELIDNO#',
							<CFOUTPUT QUERY="GetFields">
								<CFSET sValue = evaluate("Form.edt" & COLUMNNAME)>
								<CFIF ListFindnoCase(sAutoGenFld,COLUMNNAME) NEQ 0>
									<CFIF y GTE 1>
									<cfset session.11y = y>
										<CFLOOP FROM="1" TO="#y#" INDEX="sVal">
											<CFIF arrAutoGen[sVal][2] EQ COLUMNNAME>
												'#arrAutoGen[sVal][1]#'
											</CFIF>
										</CFLOOP>
									</CFIF>
								<CFELSEIF lcase(COLUMNTYPE) EQ "ftfloat" OR
											lcase(COLUMNTYPE) EQ "ftinteger">
									<CFIF sValue IS "">0<CFELSE>#sValue#</CFIF>
								<CFELSEIF lcase(COLUMNTYPE) EQ "ftcurrency">
									<CFSET sValue = Replace(sValue,",","","all")>
									<CFIF sValue IS "">0<CFELSE>#sValue#</CFIF>

								<CFELSEIF lcase(COLUMNTYPE) EQ "ftdatetime" AND Trim(sValue) IS "">
									NULL
								<CFELSEIF lcase(COLUMNTYPE) EQ "ftdatetime" AND Trim(sValue) IS NOT "">
									<CFMODULE TEMPLATE="#client.common_path#cfm_DBdateFormat.cfm" dateConvert="#sValue#">
									<CFSET sDate2 = dateResult>
									#preserveSingleQuotes(sDate2)#
								<!--- Added by Maan 09032007 to save default value of non-editable fields --->
								<CFELSEIF (ListFindNoCase(getECRTFORMSGROUP.FIELDGROUP,COLUMNNAME,"@,") EQ 0 OR ISEDITABLEEFORM EQ "N") AND ISVISIBLEEFORM EQ "Y" AND evaluate("Form.edt" & COLUMNNAME) EQ "">
									<CFMODULE TEMPLATE="#client.common_path#get_default_value.cfm" EntryValue="#DEFAULTVALUE#">
									<CFSET sValue = sDefaultValue>
									'#sValue#'
								<CFELSE>
									<!--- Added by Soti 06/14/2004 to change case of string data based on config in dataarchitect --->
									<CFIF CHARCASE EQ "ecUpperCase">
										<CFSET sValue = ucase(sValue)>
									<CFELSEIF CHARCASE EQ "ecLowerCase">
										<CFSET sValue = lcase(sValue)>
									</CFIF>
									'#sValue#'
								</CFIF>
								<CFIF CurrentRow NEQ RecordCount>,</CFIF>
							</CFOUTPUT>
							<!--- Modified by Badz - Error in saving audit trail details. 06162009 --->
							<!---,'#client.userid#'
							,#preserveSingleQuotes(sDate1)#
							,'#client.userid#'
							,#preserveSingleQuotes(sDate1)#
							,'#TimeFormat(Now(), "HH:mm:ss")#'--->
							,'#client.userid#'
							,'#sDate1#'
							,'#client.userid#'
							,'#sDate1#'
							,'#TimeFormat(Now(), "HH:mm:ss")#'
							<CFIF isDefined("GetEntry.ATTACHMENTCODE") AND GetEntry.ATTACHMENTCODE NEQ "">
								<CFSET NEWATTACHCODE=CreateUUID()>
								,'#NEWATTACHCODE#'
							</CFIF>
							<!---<CFIF lAttach>
								,'#sAttachmentCode#'
							</CFIF>--->
						)
			      	</CFQUERY>

					<CFIF nAction IS 1>
						<CFSET sMess = "Record successfully added.<BR>">
					<CFELSE>
						<CFSET sMess = "Record successfully copied.<BR>">
					</CFIF>
					<CFSET sMess=sMess & sAutoGen>
					<!--- Added by Maan 06282007 === Copy attachment from the previous file
					BUT it should have different attachmentcode so that the old file will not be
					affected with any modification in the new attachment --->
					<CFIF GetEntry.ATTACHMENTCODE NEQ "">
						<!--- Get the attached files --->
						<CFQUERY NAME="qryRplAttachments" DATASOURCE="#client.company_dsn#">
							SELECT * FROM ECINFORMSATTACH
							WHERE ATTACHMENTCODE = '#GetEntry.ATTACHMENTCODE#'
						</CFQUERY>
						<!--- Create new instance of the attachment --->
						<CFOUTPUT QUERY="qryRplAttachments">
							<CFQUERY NAME="qryNewAttachments" DATASOURCE="#client.company_dsn#">
								INSERT INTO ECINFORMSATTACH
									(ATTACHMENTCODE,ATTACHFILECODE,DESCRIPTION,EXTENSION)
								VALUES
									('#NEWATTACHCODE#','#ATTACHFILECODE#','#DESCRIPTION#','#EXTENSION#')
							</CFQUERY>
						</CFOUTPUT>
					</CFIF>
					<!--- trap errors --->
					<CFCATCH>
						<CFSET lCanAttach=false>
						<CFSET sWarn = #CFCATCH.message# & #CFCATCH.DETAIL#>
					</CFCATCH>
				</CFTRY>
			</CFIF> <!--- check if advance/late application --->
		<!---</CFIF>	  check if duplicate record --->
	<CFELSEIF nAction IS 3>
		<!--- check no. of attachments first --->
		<CFQUERY NAME="qryAttachmentCode" DATASOURCE="#table_dsn#">
			SELECT *
			FROM #GetForm.TABLENAME_FK#
			WHERE (PERSONNELIDNO = '#GetEmployee.PERSONNELIDNO#')
				<CFLOOP INDEX="x" FROM="1" TO="5">
					<CFIF evaluate("GetForm.PK_FIELD" & x) NEQ "">
						<CFSET theVal = evaluate("Form.old" & evaluate("GetForm.PK_FIELD" & x))>
						AND (#ucase(evaluate("GetForm.PK_FIELD" & x))# = '#theVal#')
					</CFIF>
				</CFLOOP>
      	</CFQUERY>

		<CFIF IsDefined("qryAttachmentCode.ATTACHMENTCODE")>
			<CFSET sAttachmentCode=qryAttachmentCode.ATTACHMENTCODE>

			<CFIF sAttachmentCode NEQ "">
				<CFQUERY NAME="qryNoOfAttachments" DATASOURCE=#client.company_dsn#>
					SELECT *
					FROM ECINFORMSATTACH
					WHERE ATTACHMENTCODE = '#sAttachmentCode#'
				</CFQUERY>

				<!--- remove file attachments --->
				<CFLOOP QUERY="qryNoOfAttachments">
					<CFIF IsDefined("form.chkDelFileAtt" & qryNoOfAttachments.CurrentRow)>
						<CFSET sAttachFileCode=Evaluate("form.chkDelFileAtt" & qryNoOfAttachments.CurrentRow)>

						<CFQUERY NAME="qryAttachments" DATASOURCE=#client.company_dsn#>
							SELECT *
							FROM ECINFORMSATTACH
							WHERE ATTACHMENTCODE = '#sAttachmentCode#' AND
								  ATTACHFILECODE = '#sAttachFileCode#'
						</CFQUERY>

						<CFIF qryAttachments.RecordCount>
							<CFSET sExpandedPath=ExpandPath("#client.attachment_path#")>

							<CFTRY>
								<CFSET lCanDelete=true>
								<CFQUERY NAME="qryECINFORMSATTACH" DATASOURCE="#client.company_dsn#">
									DELETE FROM ECINFORMSATTACH
									WHERE ATTACHMENTCODE = '#sAttachmentCode#' AND
										 ATTACHFILECODE = '#sAttachFileCode#'
								</CFQUERY>
								<!--- Added by Maan 06282007 === in connection with copying of file attachments..
								Should not delete file if some form(s) is still using it. --->
								<CFQUERY NAME="qryCheckFileCode" DATASOURCE="#client.company_dsn#">
									SELECT * FROM ECINFORMSATTACH
									WHERE ATTACHFILECODE = '#sAttachFileCode#'
								</CFQUERY>
								<CFIF qryCheckFileCode.RECORDCOUNT NEQ 0>
									<CFSET lCanDelete=false>
								</CFIF>
								<!--- the end --->
								<!--- trap errors --->
								<CFCATCH>
									<CFSET lCanDelete=false>
									<CFSET sWarn=sWarn & "Cannot delete record for file attachment #qryAttachments.DESCRIPTION# " & #CFCATCH.message# & #CFCATCH.DETAIL# & "<br>">
								</CFCATCH>
							</CFTRY>

							<CFIF lCanDelete>
								<CFFILE ACTION="DELETE" FILE="#sExpandedPath##sAttachFileCode#.#ListLast(qryAttachments.DESCRIPTION, '.')#">
							</CFIF>
						</CFIF>
					</CFIF>
				</CFLOOP>
				<CFQUERY NAME="qryNoOfLink" DATASOURCE=#client.company_dsn#>
					SELECT *
					FROM ECINFORMLINKATTACH
					WHERE ATTACHMENTCODE = '#sAttachmentCode#'
				</CFQUERY>

				<!--- remove file attachments --->
				<CFLOOP QUERY="qryNoOfLink">
					<CFIF IsDefined("form.chkDelLinkAtt" & qryNoOfLink.CurrentRow)>
						<CFSET sAttachLink=Evaluate("form.chkDelLinkAtt" & qryNoOfLink.CurrentRow)>
						<CFSET sLinkName=listgetat(sAttachLink, "1", "~")>
						<CFSET sLinkVal=listgetat(sAttachLink, "2", "~")>
						<CFQUERY NAME="qryAttachments" DATASOURCE=#client.company_dsn#>
							SELECT *
							FROM ECINFORMLINKATTACH
							WHERE ATTACHMENTCODE = '#sAttachmentCode#' AND
								  LINKNAME = '#sLinkName#' AND
								  LINKVALUE = '#sLinkVal#'
						</CFQUERY>

						<CFIF qryAttachments.RecordCount>

							<CFTRY>
								<CFQUERY NAME="qryECINFORMSATTACH" DATASOURCE="#client.company_dsn#">
									DELETE FROM ECINFORMLINKATTACH
									WHERE ATTACHMENTCODE = '#sAttachmentCode#' AND
									  LINKNAME = '#sLinkName#' AND
									  LINKVALUE = '#sLinkVal#'
						      	</CFQUERY>

								<!--- trap errors --->
								<CFCATCH>
									<CFSET lCanDelete=false>
									<CFSET sWarn=sWarn & "Error in Deleting Link Attachment" & "<br>">
								</CFCATCH>
							</CFTRY>
						</CFIF>
					</CFIF>
				</CFLOOP>
			</CFIF>
		</CFIF>

		<!--- check for late application --->
		<CFIF GetForm.FLDFORLATEAPPS NEQ "" AND Evaluate("IsDefined('Form.edt" & GetForm.FLDFORLATEAPPS & "')")>
			<!--- Get the application date --->
			<CFQUERY NAME="GetEntry" DATASOURCE="#table_dsn#" MAXROWS=1>
		    	SELECT *
				FROM #GetForm.TABLENAME_FK#
				WHERE
					(PERSONNELIDNO = '#GetEmployee.PERSONNELIDNO#')
					<CFLOOP  INDEX="x" FROM="1" TO="5">
						<CFIF evaluate("GetForm.PK_FIELD" & x) NEQ "">
							<CFSET theVal = evaluate("Form.old" & evaluate("GetForm.PK_FIELD" & x))>
							AND (#ucase(evaluate("GetForm.PK_FIELD" & x))# = '#theVal#')
						</CFIF>
					</CFLOOP>
			</CFQUERY>

			<CFIF NOT(GetEntry.RecordCount)>
				<CFMODULE TEMPLATE="#client.common_path#cfm_error.cfm" MODULE="#session.tabid#" TYPE="ILLEGAL">
			</CFIF>

			<CFSET sValue=Evaluate("Form.edt" & GetForm.FLDFORLATEAPPS)>
			<CFIF Trim(sValue) IS "">
				<CFSET sValue="01/01/1900">
			</CFIF>

			<CFSET dCutOffDate=GetEntry.RECDATECREATED>

			<CFIF GetForm.GRACEPRDLATEAPPS NEQ "" AND GetForm.GRACEPRDLATEAPPS NEQ 0>
				<CFIF GetForm.LATEAPPSMODE IS 1>
					<CFSET nGracePrd=(GetForm.GRACEPRDLATEAPPS * -1)>
				<CFELSE>
					<CFSET nGracePrd=GetForm.GRACEPRDLATEAPPS>
				</CFIF>
				<CFSET dCutOffDate=DateAdd("d", nGracePrd, dCutOffDate)>
			</CFIF>

			<CFSET nValue=DateCompare(dCutOffDate, sValue, "d")>
		<CFELSE>
			<CFSET nValue=1000>
		</CFIF>

		<CFIF (nValue IS 1 OR nValue IS 0) AND GetForm.LATEAPPSMODE IS "1">
			<CFSET sWarn = "Late Application is not accepted. Operation aborted.<BR>">
		<CFELSEIF (nValue IS -1 OR nValue IS 0) AND GetForm.LATEAPPSMODE IS "2">
			<CFSET sWarn = "Advance Application is not accepted. Operation aborted.<BR>">
		<CFELSE>
			<CFTRY>
				<CFSET sAuditAction="E">
				<CFSET qryAuditFields=GetFields>
				<CFSET sAuditTablename=GetForm.TABLENAME_FK>
				<CFSET sAuditTableLevel=GetLevelID.LEVELID>
				<CFQUERY NAME="qryAuditGetOldValue" DATASOURCE="#table_dsn#">
					SELECT *
					FROM #GetForm.TABLENAME_FK#
					WHERE (PERSONNELIDNO = '#GetEmployee.PERSONNELIDNO#')
					<CFLOOP  INDEX="x" FROM="1" TO="5">
						<CFIF evaluate("GetForm.PK_FIELD" & x) NEQ "">
							<CFSET theVal = evaluate("Form.old" & evaluate("GetForm.PK_FIELD" & x))>
							AND (#ucase(evaluate("GetForm.PK_FIELD" & x))# = '#theVal#')
						</CFIF>
					</CFLOOP>
	      		</CFQUERY>
				<CFLOOP QUERY="GetFields">
					<CFIF #COLUMNTYPE# EQ "ftMemo">
						<CFSET myColType="ftMemo">
						<CFBREAK>
					<CFELSE>
						<CFSET myColType="ftString">
					</CFIF>
				</CFLOOP>
				<!---revised last 08/10/2011--->
				<!---To resolve the error in file attachment--->
				<!--start--->
				<CFINCLUDE TEMPLATE="_audittraildata.cfm">
				<!---end--->

				<CFSET lCanAttach=true>
				<CFQUERY NAME="UpdateEntry" DATASOURCE="#table_dsn#">
					UPDATE #GetForm.TABLENAME_FK#
					SET
						<CFOUTPUT QUERY="GetFields">
							<CFSET sValue = evaluate("Form.edt" & COLUMNNAME)>
							<CFIF lcase(COLUMNTYPE) EQ "ftfloat" OR
										lcase(COLUMNTYPE) EQ "ftinteger">
								#COLUMNNAME# = <CFIF sValue IS "">0<CFELSE>#sValue#</CFIF>
							<CFELSEIF lcase(COLUMNTYPE) EQ "ftcurrency">
								<CFSET sValue = Replace(sValue,",","","all")>
								#COLUMNNAME# = <CFIF sValue IS "">0<CFELSE>#sValue#</CFIF>
							<CFELSEIF lcase(COLUMNTYPE) EQ "ftdatetime" AND Trim(sValue) IS "">
								#COLUMNNAME# = NULL
							<CFELSEIF lcase(COLUMNTYPE) EQ "ftdatetime" AND Trim(sValue) IS NOT "">
								<CFMODULE TEMPLATE="#client.common_path#cfm_DBdateFormat.cfm" dateConvert="#sValue#">
								<CFSET sDate2 = dateResult>
								#COLUMNNAME# = #preserveSingleQuotes(sDate2)#
							<!--- Added by Maan 09032007, save default values of non-editable fields --->
							<CFELSEIF (ListFindNoCase(getECRTFORMSGROUP.FIELDGROUP,COLUMNNAME,"@,") EQ 0 OR ISEDITABLEEFORM EQ "N") AND ISVISIBLEEFORM EQ "Y" AND evaluate("Form.edt" & COLUMNNAME) EQ "">
								<CFMODULE TEMPLATE="#client.common_path#get_default_value.cfm" EntryValue="#DEFAULTVALUE#">
								<CFSET sValue = sDefaultValue>
								#COLUMNNAME# = '#sValue#'
							<CFELSE>
								<!--- Added by Soti 06/14/2004 to change case of string data based on config in dataarchitect --->
								<CFIF CHARCASE EQ "ecUpperCase">
									<CFSET sValue = ucase(sValue)>
								<CFELSEIF CHARCASE EQ "ecLowerCase">
									<CFSET sValue = lcase(sValue)>
								</CFIF>
								#COLUMNNAME# = '#sValue#'
							</CFIF>
							<CFIF CurrentRow NEQ RecordCount>,</CFIF>
						</CFOUTPUT>
						,USERID = '#client.userid#'
						,DATELASTUPDATE = '#preserveSingleQuotes(sDate1)#'
						,TIMELASTUPDATE = '#TimeFormat(Now(), "HH:mm:ss")#'
						<CFIF IsDefined("sAttachmentCode") AND sAttachmentCode IS "">
							<CFSET sAttachmentCode=CreateUUID()>
							,ATTACHMENTCODE = '#sAttachmentCode#'
						</CFIF>
					WHERE
						(PERSONNELIDNO = '#GetEmployee.PERSONNELIDNO#')
						<CFLOOP  INDEX="x" FROM="1" TO="5">
							<CFIF evaluate("GetForm.PK_FIELD" & x) NEQ "">
								<CFSET theVal = evaluate("Form.old" & evaluate("GetForm.PK_FIELD" & x))>
								AND (#ucase(evaluate("GetForm.PK_FIELD" & x))# = '#theVal#')
							</CFIF>
						</CFLOOP>
		      	</CFQUERY>
				<CFSET sMess = "Record successfully updated.<BR>">
				<CFCATCH TYPE="Any">
					<CFSET lCanAttach=false>
					<CFSET sWarn = #CFCATCH.message# & #CFCATCH.DETAIL#>
				</CFCATCH>
			</CFTRY>
		</CFIF>
	<CFELSEIF nAction IS 4>
		<!--- get destination eform --->
		<CFQUERY NAME="qryCopyToeForm" DATASOURCE=#client.company_dsn#>
			SELECT *
			FROM ECRGFORMS
			WHERE FORMCODE = '#GetForm.COPYTOFORMCODE#'
		</CFQUERY>
		<!--- get database level for destination table --->
		<CFQUERY NAME="qryGRGBOSETABLE" DATASOURCE="#client.global_dsn#">
			SELECT LEVELID
			FROM GRGBOSETABLE
			WHERE TABLENAME = '#qryCopyToeForm.TABLENAME_FK#'
		</CFQUERY>

		<CFIF NOT(qryGRGBOSETABLE.RecordCount)>
			<CFMODULE TEMPLATE="#client.common_path#cfm_error.cfm" MODULE="#session.tabid#" TYPE="ERR_DATA">
		</CFIF>

		<!--- get table location --->
		<!--- custom tag: parameter: DBLEVEL; return value: DSN --->
		<CFMODULE TEMPLATE="#client.common_path#cfm_leveldsn.cfm" DBLEVEL="#qryGRGBOSETABLE.LEVELID#">
		<CFSET copytoeform_dsn = DSN>

		<!--- check for existence --->
		<CFQUERY NAME="IsExist" DATASOURCE=#copytoeform_dsn#>
	  		SELECT COUNT(*) AS RECCOUNT
			FROM #qryCopyToeForm.TABLENAME_FK#
			WHERE
				(PERSONNELIDNO = '#GetEmployee.PERSONNELIDNO#')
				<CFLOOP  INDEX="x" FROM="1" TO="5">
					<CFIF evaluate("qryCopyToeForm.PK_FIELD" & x) NEQ "">
						<CFSET theVal = evaluate("Form.edt" & evaluate("qryCopyToeForm.PK_FIELD" & x))>
						AND (#ucase(evaluate("qryCopyToeForm.PK_FIELD" & x))# = '#theVal#')
					</CFIF>
				</CFLOOP>
	  	</CFQUERY>
		<CFQUERY NAME="GetCopytoeFormFields" DATASOURCE="#client.global_dsn#">
			SELECT COLUMNNAME, COLUMNDESC, COLUMNTYPE, FIELDGROUP, COLUMNORDER, CHARCASE
			FROM GRGBOSETABLEFIELDS
			WHERE 	(TABLENAME = '#qryCopyToeForm.TABLENAME_FK#') AND
				(ISVISIBLEEFORM    = 'Y' OR ISVISIBLEEFORM IS NULL) AND
				(COLUMNNAME <> 'PERSONNELIDNO') AND
				(COLUMNNAME <> 'RECDATECREATED') AND
				(COLUMNNAME <> 'RECCREATEDBY') AND
				(COLUMNNAME <> 'USERID') AND
				(COLUMNNAME <> 'DATELASTUPDATE') AND
				(COLUMNNAME <> 'TIMELASTUPDATE') AND
				(COLUMNNAME <> 'ROUTEID') AND
				(COLUMNNAME <> 'APPROVED') AND
				(LEN(COLUMNDESC) > 0) AND
		
				(COLUMNNAME <> 'ATTACHMENTCODE')
				ORDER BY FIELDGROUP, COLUMNORDER, COLUMNDESC, COLUMNNAME
		</CFQUERY>
		<CFSET arrCTEAutoGen = ArrayNew(2)>
		<CFSET sAutoGenFld = "">
		<CFSET x = 1>
		<CFLOOP QUERY="GetCopytoeFormFields">
			<CFQUERY DATASOURCE="#client.global_dsn#" NAME="qryCTEGSTAUTOGENFIELD">
				SELECT *
				FROM GSTAUTOGENFIELD
				WHERE TABLENAME = '#qryCopyToeForm.TABLENAME_FK#' AND
					  FIELDNAME = '#GetCopytoeFormFields.COLUMNNAME#'
			</CFQUERY>
			<CFIF qryCTEGSTAUTOGENFIELD.RECORDCOUNT>
				<CFSET sAutoGenFld = ListAppend(sAutoGenFld,qryCTEGSTAUTOGENFIELD.FIELDNAME)>
				<CFIF qryCTEGSTAUTOGENFIELD.WITHDATE NEQ "N">
					<CFMODULE TEMPLATE="#client.common_path#autogenfield.cfm"
						SEEDKEY="#qryCTEGSTAUTOGENFIELD.SEEDKEY#"
						CODELENGTH="#qryCTEGSTAUTOGENFIELD.CODELENGTH#"
						COLUMNNAME="#qryCTEGSTAUTOGENFIELD.FIELDNAME#"
						TABLENAME_FK="#qryCopyToeForm.TABLENAME_FK#"
						DATASOURCE="#copytoeform_dsn#"
						WITHDATE="#qryCTEGSTAUTOGENFIELD.WITHDATE#">
						<CFSET sValue=AUTOGENVALUE>
						<cfset arrCTEAutoGen[x][1] = sValue>
						<cfset arrCTEAutoGen[x][2] = qryCTEGSTAUTOGENFIELD.FIELDNAME>
						<CFSET x = x + 1>
				<CFELSE>
				<!--- WITHDATE eq "N" --->
					<CFMODULE TEMPLATE="#client.common_path#cfm_autogen_bose.cfm"
						COLUMNNAME="#qryCTEGSTAUTOGENFIELD.FIELDNAME#"
						TABLENAME="#qryCopyToeForm.TABLENAME_FK#"
						DATASOURCE="#copytoeform_dsn#">  
						<CFSET sValue=AUTOGENVALUE>
						<CFSET arrCTEAutoGen[x][1] = sValue>
						<CFSET arrCTEAutoGen[x][2] = qryCTEGSTAUTOGENFIELD.FIELDNAME>
						<CFSET x = x + 1>
				</CFIF>
			</CFIF>
		</CFLOOP>
		<!--- there are duplicate records ---
		<CFIF IsExist.RECCOUNT NEQ 0>
			--- Re-create autogen by Maan 08302007 ---
			<CFSET sAutoGen="">
			<CFQUERY NAME="GetCopytoeFormFields" DATASOURCE="#client.global_dsn#">
				SELECT COLUMNNAME, COLUMNDESC, COLUMNTYPE
				FROM GRGBOSETABLEFIELDS
				WHERE TABLENAME = '#qryCopyToeForm.TABLENAME_FK#'
			</CFQUERY>
			<CFLOOP QUERY="GetCopytoeFormFields">
				<CFQUERY DATASOURCE="#client.global_dsn#" NAME="qryCTEGSTAUTOGENFIELD">
					SELECT *
					FROM GSTAUTOGENFIELD
					WHERE TABLENAME = '#qryCopyToeForm.TABLENAME_FK#' AND
						  FIELDNAME = '#GetCopytoeFormFields.COLUMNNAME#'
				</CFQUERY>
				<CFIF qryCTEGSTAUTOGENFIELD.RECORDCOUNT>
					<CFIF qryCTEGSTAUTOGENFIELD.WITHDATE EQ "Y">
						<CFMODULE TEMPLATE="#client.common_path#autogenfield.cfm"
							SEEDKEY="#qryCTEGSTAUTOGENFIELD.SEEDKEY#"
							CODELENGTH="#qryCTEGSTAUTOGENFIELD.CODELENGTH#"
							COLUMNNAME="#GetCopytoeFormFields.COLUMNNAME#"
							TABLENAME_FK="#qryCopyToeForm.TABLENAME_FK#"
							DATASOURCE="#table_dsn#"
							WITHDATE="#qryCTEGSTAUTOGENFIELD.WITHDATE#">
							<CFSET sValue=AUTOGENVALUE>
							<CFIF sValue NEQ Evaluate("Form.edt" & GetCopytoeFormFields.COLUMNNAME)>
								<CFSET xDummy=Evaluate("Form.edt" & GetCopytoeFormFields.COLUMNNAME & "='" & sValue & "'")>
								<CFSET sAutoGen=sAutoGen & "#GetCopytoeFormFields.COLUMNDESC# was changed to #sValue#.<BR>">
							</CFIF>
					<CFELSE>
					--- WITHDATE eq "N" ---
						<CFMODULE TEMPLATE="#client.common_path#cfm_autogen_bose.cfm"
							COLUMNNAME="#GetCopytoeFormFields.COLUMNNAME#"
							TABLENAME="#qryCopyToeForm.TABLENAME_FK#">  
						<CFSET sValue=AUTOGENVALUE>
					</CFIF>
				</CFIF>
			</CFLOOP>
			---<CFSET sWarn = "Duplicate record found. Operation aborted.<BR>">---
			<CFSET sMess=sAutoGen & "#GetCopytoeFormFields.COLUMNDESC# was changed to #sValue#.<BR>">
		</CFIF>--->
			<!--- check for late application --->
			<CFIF qryCopyToeForm.FLDFORLATEAPPS NEQ "" AND Evaluate("IsDefined('Form.edt" & qryCopyToeForm.FLDFORLATEAPPS & "')")>
				<CFSET sValue=Evaluate("Form.edt" & qryCopyToeForm.FLDFORLATEAPPS)>
				<CFIF Trim(sValue) IS "">
					<CFSET sValue="01/01/1900">
				</CFIF>
				<CFSET dCutOffDate=Now()>

				<CFIF qryCopyToeForm.GRACEPRDLATEAPPS NEQ "" AND qryCopyToeForm.GRACEPRDLATEAPPS NEQ 0>
					<CFIF GetForm.LATEAPPSMODE IS 1>
						CFSET nGracePrd=(GetForm.GRACEPRDLATEAPPS * -1)>
					<CFELSE>
						<CFSET nGracePrd=GetForm.GRACEPRDLATEAPPS>
					</CFIF>
					<CFSET dCutOffDate=DateAdd("d", nGracePrd, dCutOffDate)>
				</CFIF>

				<CFSET nValue=DateCompare(dCutOffDate, sValue, "d")>
			<CFELSE>
				<CFSET nValue=1000>
			</CFIF>

			<CFIF (nValue IS 1 OR nValue IS 0) AND GetForm.LATEAPPSMODE IS "1">
				<CFSET sWarn = "Late Application is not accepted. Operation aborted.<BR>">
			<CFELSEIF (nValue IS -1 OR nValue IS 0) AND GetForm.LATEAPPSMODE IS "2">
				<CFSET sWarn = "Advance Application is not accepted. Operation aborted.<BR>">
			<CFELSE>
				<CFTRY>
					<!--- audit trail --->
					<CFSET sAuditAction="A">
					<CFSET qryAuditFields=GetFields>
					<CFSET sAuditTablename=qryCopyToeForm.TABLENAME_FK>
					<CFSET sAuditTableLevel=qryGRGBOSETABLE.LEVELID>
					<CFSET aAuditExtraField=ArrayNew(2)>
					<CFSET aAuditExtraField[1][1]="PERSONNELIDNO">
					<CFSET aAuditExtraField[1][2]="#GetEmployee.PERSONNELIDNO#">
					<CFLOOP QUERY="GetCopytoeFormFields">
						<CFIF #COLUMNTYPE# EQ "ftMemo">
							<CFSET myColType="ftMemo">
							<CFBREAK>
						<CFELSE>
							<CFSET myColType="ftString">
						</CFIF>
					</CFLOOP>
					<CFINCLUDE TEMPLATE="../audittrail/_audittraildata.cfm">

					<CFSET lCanAttach=true>
					<!---<CFSET sAttachmentCode=CreateUUID()>--->
					<CFSET x = x - 1>
					<CFQUERY NAME="InsertEntry" DATASOURCE="#copytoeform_dsn#">
						INSERT
						INTO #qryCopyToeForm.TABLENAME_FK# (PERSONNELIDNO,
							<CFOUTPUT QUERY="GetCopytoeFormFields">
								#COLUMNNAME#,
							</CFOUTPUT>
							RECCREATEDBY
							,RECDATECREATED
							,USERID
							,DATELASTUPDATE
							,TIMELASTUPDATE
							<CFIF lAttach>
								,ATTACHMENTCODE
							</CFIF>
						) VALUES (
							'#GetEmployee.PERSONNELIDNO#',
							<CFOUTPUT QUERY="GetCopytoeFormFields">
								<CFSET sValue = evaluate("Form.edt" & COLUMNNAME)>
								<CFIF ListFindnoCase(sAutoGenFld,COLUMNNAME) NEQ 0>
									<CFIF x GTE 1>
										<CFLOOP FROM="1" TO="#x#" INDEX="sVal">
											<CFIF arrCTEAutoGen[sVal][2] EQ COLUMNNAME>
												'#arrCTEAutoGen[sVal][1]#'
											</CFIF>
										</CFLOOP>
									</CFIF>
								<CFELSEIF lcase(COLUMNTYPE) EQ "ftfloat" OR
											lcase(COLUMNTYPE) EQ "ftinteger">
									#sValue#
								<CFELSEIF lcase(COLUMNTYPE) EQ "ftcurrency">
									<CFSET sValue = Replace(sValue,",","","all")>
									<CFIF sValue IS "">0<CFELSE>#sValue#</CFIF>
								<CFELSEIF lcase(COLUMNTYPE) EQ "ftdatetime" AND Trim(sValue) IS "">
									NULL
								<CFELSEIF lcase(COLUMNTYPE) EQ "ftdatetime" AND Trim(sValue) IS NOT "">
									<CFMODULE TEMPLATE="#client.common_path#cfm_DBdateFormat.cfm" dateConvert="#sValue#">
									<CFSET sDate2 = dateResult>
									#preserveSingleQuotes(sDate2)#
								<CFELSE>
									'#sValue#'
								</CFIF>
								<CFIF CurrentRow NEQ RecordCount>,</CFIF>
							</CFOUTPUT>
							,'#client.userid#'
							,#preserveSingleQuotes(sDate1)#
							,'#client.userid#'
							,#preserveSingleQuotes(sDate1)#
							,'#TimeFormat(Now(), "HH:mm:ss")#'
							<CFIF lAttach>
								,'#urlAttach#'
							</CFIF>
						)
						</CFQUERY>
					<CFIF x GTE 1>
						<CFSET sMess1 = "">
						<CFLOOP FROM="1" TO="#x#" INDEX="nVal">
							<CFIF evaluate("Form.edt" & arrCTEAutoGen[nVal][2]) NEQ arrCTEAutoGen[nVal][1]>
								<CFSET sMess1 = arrCTEAutoGen[nVal][2] & " was changed to: " & arrCTEAutoGen[nVal][1] & ".">
								<CFSET sMess = ListAppend(sMess,sMess1,"<br>")>
							</CFIF>
						</CFLOOP>
						<CFSET sMess = "Record successfully copied.<br>" & sMess1>
					<CFELSE>
						<CFSET sMess = "Record successfully copied.<BR>">
					</CFIF>
					<CFQUERY NAME="qryCHECKMAIN" DATASOURCE=#client.company_dsn#>
						SELECT *
						FROM ECRGFORMS
						WHERE COPYTOFORMCODE = '#GetForm.COPYTOFORMCODE#'
					</CFQUERY>
					<CFLOOP INDEX="x" FROM="1" TO="5">
						<CFIF evaluate("qryCHECKMAIN.PK_FIELD" & x) NEQ "">

							<CFQUERY NAME="qryUpdateApproved" DATASOURCE=#client.company_dsn#>
								UPDATE #GetForm.TABLENAME_FK#
								SET APPROVED='C'
								WHERE (#ucase(evaluate("qryCHECKMAIN.PK_FIELD" & x))# = '#form.hidAutoVal#')<!--- '#session.sufvalue#') ... Modified by Maan 09042007, should get value from url or form, not session --->
							</CFQUERY>
						</CFIF>
					</CFLOOP>
					<!--- trap errors --->
					<CFCATCH type="database">
						<CFSET lCanAttach=false>
						<CFSET sWarn = #CFCATCH.message# & #CFCATCH.DETAIL# & #CFCATCH.SQL#>
					</CFCATCH>
				</CFTRY>
			</CFIF>
	</CFIF><!---
	<cfoutput>#lAttach#<br />#lCanAttach#</cfoutput><cfabort>--->
	<CFIF lAttach AND lCanAttach>
		<CFLOOP FROM=1 TO=6 INDEX="x">
			<CFIF IsDefined("form.eformfileattachment" & x)>
				<CFIF Trim(Evaluate("form.eformfileattachment#x#")) NEQ "">
					<CFSET sExpandedPath=ExpandPath("#client.attachment_path#")>

					<!--- Check if attachment directory is exist or not 	By: Winston ---->
					<CFIF NOT DirectoryExists("#expandpath(client.attachment_path)#")>
						<CFDIRECTORY ACTION="Create" DIRECTORY="#expandpath(client.attachment_path)#">
						<CFSET sMess = "Attachment path created...">
					</CFIF>

					<CFFILE ACTION="UPLOAD"
						FILEFIELD="form.eformfileattachment#x#"
						DESTINATION="#sExpandedPath#"
						NAMECONFLICT="Overwrite">
					<CFIF File.FileWasSaved>
						<CFSET sAttempted=File.AttemptedServerFile>
						<!---modified by mico 01202010 because file cannot be found if the filename extension is included in the attachfilecode --->
						<CFSET Filename="#File.ServerFileName#">
						<!---<CFSET EXTENSION = ListLast(Filename,'.')>--->
						<CFSET EXTENSION = "." & "#File.serverFileExt#">
						<!---end of mico modification 01202010--->
						<!--- delete any files in extensions that are not allowed --->
						<CFIF LCase(EXTENSION) eq "cfm" OR
							  LCase(EXTENSION) eq "cfml" OR
							  LCase(EXTENSION) eq "dbm" OR
							  LCase(EXTENSION) eq "dbml" OR
							  LCase(EXTENSION) eq "cgi" OR
							  LCase(EXTENSION) eq "pl" OR
							  LCase(EXTENSION) eq "plx" OR
							  LCase(EXTENSION) eq "asp" OR
						 	  LCase(EXTENSION) eq "js" OR
							  LCase(EXTENSION) eq "exe" OR
							  LCase(EXTENSION) eq "com" OR
							  LCase(EXTENSION) eq "vbs" OR
							  LCase(EXTENSION) eq "vb">
							<CFFILE ACTION="DELETE" FILE="#sExpandedPath##Filename#">
							<CFSET sWarn=sWarn & "Attached file (#sAttempted#) is not allowed.<br>">
						<CFELSE>
							<CFTRY>
								<CFSET lCanRename=true>
								<CFSET sFileAttachCode=CreateUUID()>
								<CFQUERY NAME="qryECINFORMSATTACH" DATASOURCE="#client.company_dsn#">
									INSERT INTO ECINFORMSATTACH
										(ATTACHMENTCODE,
										 ATTACHFILECODE,
										 DESCRIPTION)
									VALUES
										('#sAttachmentCode#',
										 <!---'#sFileAttachCode#',--->
										 '#Filename#',
										 '#PreserveSingleQuotes(sAttempted)#')
								 </CFQUERY>

								<!--- trap errors --->
								<CFCATCH>
									<CFSET lCanRename=false>
									<CFSET sWarn=sWarn & "Cannot save record for file attachment #sAttempted# " & #CFCATCH.message# & #CFCATCH.DETAIL# & "<br>">
								</CFCATCH>
							</CFTRY>

							<CFIF not lCanRename>
								<!---<CFFILE ACTION="Rename" SOURCE="#sExpandedPath##Filename#" DESTINATION="#sExpandedPath##Filename#.#EXTENSION#">
							<CFELSE>--->
								<CFFILE ACTION="DELETE" FILE="#sExpandedPath##Filename#">
							</CFIF>
						</CFIF> <!--- file is allowed --->
					</CFIF> <!--- file was saved --->
				</CFIF> <!--- filex has attachment --->
			</CFIF> <!--- filex has attachment --->
			<CFIF IsDefined("form.eformlinkdesc" & x) AND IsDefined("form.eformlinkattach" & x)><!---link attachment--->
				<CFIF Trim(Evaluate("form.eformlinkattach#x#")) NEQ "http://" AND Evaluate("form.eformlinkdesc#x#") NEQ "">
					<CFSET sLinkDesc=EVALUATE("form.eformlinkdesc" & x)>
					<CFSET sLinkVal=EVALUATE("form.eformlinkattach" & x)>
					<CFQUERY NAME="qryExistLinkAttach" DATASOURCE="#client.company_dsn#">
						SELECT *
						FROM ECINFORMLINKATTACH
						WHERE ATTACHMENTCODE='#sAttachmentCode#'
							AND LINKNAME='#sLinkDesc#'
							AND LINKVALUE='#sLinkVal#'
					 </CFQUERY>
					 <CFIF NOT qryExistLinkAttach.RECORDCOUNT>
						 <CFTRY>

							<CFQUERY NAME="qryECINFORMSATTACH" DATASOURCE="#client.company_dsn#">
								INSERT INTO ECINFORMLINKATTACH
									(ATTACHMENTCODE,
									 LINKNAME,
									 LINKVALUE,
									 RECCREATEDBY
									,RECDATECREATED
									,USERID
									,DATELASTUPDATE
									,TIMELASTUPDATE
									 )
								VALUES
									('#sAttachmentCode#',
									 '#sLinkDesc#',
									 '#sLinkVal#',
									 '#client.userid#',
									 '#sDate1#',
									 '#client.userid#',
									 '#sDate1#',
									 '#TimeFormat(Now(), "HH:mm:ss")#')
							 </CFQUERY>

							<!--- trap errors --->
							<CFCATCH>
								<CFSET sWarn=sWarn & "Error saving link attachment<br>">
							</CFCATCH>
						</CFTRY>
					</CFIF>
				</CFIF>
			</CFIF><!---link attachment--->
		</CFLOOP> <!--- loop 3x for file upload --->
	</CFIF> <!--- proceed with attachment --->
